package com.yc.demo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "MathServlet", value = "/MathServlet")
public class MathServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        final String a = request.getParameter("a");
        final String b = request.getParameter("b");
        int ia = Integer.valueOf(a);
        int ib = Integer.valueOf(b);
        final String op = request.getParameter("op");
        if("+".equals(op)){
            response.getWriter().print(ia+ib);
        }else if("-".equals(op)){
            response.getWriter().print(ia-ib);
        }else if("*".equals(op)){
            response.getWriter().print(ia*ib);
        }else{
            response.getWriter().print(ia/ib);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
